| Conditions | 1 |
| Paths | 1 |
| Total Lines | 169 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 9 | ||
| Bugs | 2 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var chai = require('chai'); |
||
| 6 | describe('Request', function() { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Sql.getAllAttributes |
||
| 10 | * |
||
| 11 | */ |
||
| 12 | it('Util.getAllAttributes()', function(done) { |
||
| 13 | |||
| 14 | var attributes = Util.getAllAttributes("{{abe type='data' key='top_things_slider_highlight' desc='Automatic slider' source='select * from ../' editable='false'}}", {}) |
||
| 15 | |||
| 16 | chai.assert.equal(attributes.sourceString, 'select * from ../', 'sourceString is ok') |
||
| 17 | done(); |
||
| 18 | }); |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Sql.executeQuery |
||
| 22 | * |
||
| 23 | */ |
||
| 24 | it('Sql.executeQuery()', function(done) { |
||
| 25 | try { |
||
| 26 | |||
| 27 | var match = 'select * from ../' |
||
| 28 | var jsonPage = {} |
||
|
|
|||
| 29 | var res = Sql.handleSqlRequest(match, {}) |
||
| 30 | |||
| 31 | chai.assert.equal(res.string, 'select ["*"] from ["___abe_dot______abe_dot______abe___"] ', 'select not well formatted') |
||
| 32 | done(); |
||
| 33 | } catch (x) { |
||
| 34 | done(x); |
||
| 35 | } |
||
| 36 | }); |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Sql.executeFromClause |
||
| 40 | * |
||
| 41 | */ |
||
| 42 | it('Sql.executeFromClause()', function() { |
||
| 43 | |||
| 44 | Manager.instance.setList([ |
||
| 45 | {"path": "data/test.json", "publish": true}, |
||
| 46 | {"path": "data/truc/test.json", "publish": true} |
||
| 47 | ]) |
||
| 48 | |||
| 49 | var from = ["/truc"] |
||
| 50 | var res = Sql.executeFromClause(from, from) |
||
| 51 | |||
| 52 | chai.expect(res).to.have.length(1); |
||
| 53 | }); |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Sql.executeWhereClause |
||
| 57 | * |
||
| 58 | */ |
||
| 59 | it('Sql.executeWhereClause()', function() { |
||
| 60 | var files = [ |
||
| 61 | {"publish": {"abe_meta": {"template": "test"}}}, |
||
| 62 | {"publish": {"abe_meta": {"template": "truc"}}} |
||
| 63 | ]; |
||
| 64 | var where = [{ left: 'template', right: 'test', compare: '=', operator: '' }] |
||
| 65 | |||
| 66 | var res = Sql.executeWhereClause(files, where, -1, ['*'], {}) |
||
| 67 | |||
| 68 | chai.expect(res).to.have.length(1); |
||
| 69 | }); |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Sql.whereEquals |
||
| 73 | * |
||
| 74 | */ |
||
| 75 | it('Sql.whereEquals()', function() { |
||
| 76 | var json = {"template": "test", "title": "test"} |
||
| 77 | |||
| 78 | chai.expect(json) |
||
| 79 | .to.deep.equal( |
||
| 80 | Sql.whereEquals( |
||
| 81 | [{ left: 'template' }], |
||
| 82 | json.template, |
||
| 83 | "test", |
||
| 84 | json |
||
| 85 | ) |
||
| 86 | ); |
||
| 87 | |||
| 88 | chai.expect(json) |
||
| 89 | .to.deep.equal( |
||
| 90 | Sql.whereEquals( |
||
| 91 | [{ left: 'title' }], |
||
| 92 | json.title, |
||
| 93 | "test", |
||
| 94 | json |
||
| 95 | ) |
||
| 96 | ); |
||
| 97 | |||
| 98 | chai.expect(json) |
||
| 99 | .to.not.deep.equal( |
||
| 100 | Sql.whereEquals( |
||
| 101 | [{ left: 'title' }], |
||
| 102 | json.title, |
||
| 103 | "ttt", |
||
| 104 | json |
||
| 105 | ) |
||
| 106 | ); |
||
| 107 | }); |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Sql.whereNotEquals |
||
| 111 | * |
||
| 112 | */ |
||
| 113 | it('Sql.whereNotEquals()', function() { |
||
| 114 | var json = {"template": "truc", "title": "truc"} |
||
| 115 | |||
| 116 | chai.expect(json) |
||
| 117 | .to.deep.equal( |
||
| 118 | Sql.whereNotEquals( |
||
| 119 | [{ left: 'template' }], |
||
| 120 | json.template, |
||
| 121 | "test", |
||
| 122 | json |
||
| 123 | ) |
||
| 124 | ); |
||
| 125 | |||
| 126 | chai.expect(json) |
||
| 127 | .to.deep.equal( |
||
| 128 | Sql.whereNotEquals( |
||
| 129 | [{ left: 'title' }], |
||
| 130 | json.title, |
||
| 131 | "test", |
||
| 132 | json |
||
| 133 | ) |
||
| 134 | ); |
||
| 135 | |||
| 136 | chai.expect(json) |
||
| 137 | .to.not.deep.equal( |
||
| 138 | Sql.whereNotEquals( |
||
| 139 | [{ left: 'template' }], |
||
| 140 | json.title, |
||
| 141 | "truc", |
||
| 142 | json |
||
| 143 | ) |
||
| 144 | ); |
||
| 145 | }); |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Sql.whereLike |
||
| 149 | * |
||
| 150 | */ |
||
| 151 | it('Sql.whereLike()', function() { |
||
| 152 | var json = {"template": "test", "title": "test"} |
||
| 153 | |||
| 154 | chai.expect(json) |
||
| 155 | .to.deep.equal( |
||
| 156 | Sql.whereLike( |
||
| 157 | [{ left: 'template' }], |
||
| 158 | json.template, |
||
| 159 | "te", |
||
| 160 | json |
||
| 161 | ) |
||
| 162 | ); |
||
| 163 | |||
| 164 | chai.expect(json) |
||
| 165 | .to.not.deep.equal( |
||
| 166 | Sql.whereLike( |
||
| 167 | [{ left: 'title' }], |
||
| 168 | json.title, |
||
| 169 | "tu", |
||
| 170 | json |
||
| 171 | ) |
||
| 172 | ); |
||
| 173 | }); |
||
| 174 | }); |
||
| 175 |